<?php $this->load->view('inc/header'); ?>

<!--content1-->
<div class="grid_12" style="background-color:#CCCCCC;">

<div class="grid_4 alpha">
  <!-- group search -->
  <div class="grid_4 alpha" style="margin-top:10px;">
    <div id="side-panel-top">
    	<div style="padding-left: 22px; padding-top: 7px; font-weight: bold; color:#666666;">Group Search</div>
    </div>
    <div id="side-panel-middle"> dfgdg </div>
    <div id="side-panel-bottom"></div>
  </div> 
	<!-- search -->

   <!-- create new cop gorup area-->
   <?php
   	if($this->session->userdata('is_logged_in') || $this->session->userdata('is_logged_in')==true){
   ?>
    <div class="grid_4 alpha" style="margin-top:8px;">
      <div id="side-panel-top">
      	<div style="padding-left: 22px; padding-top:7px; color: rgb(0, 0, 0); font-weight: bold; color:#FF6633;">Cops Tool's</div>
      </div>
      <div id="side-panel-middle">
      	<div id="tools" style="padding-left:25px;"><ul><li><a href="<?=base_url()?>cops/create_cops">Create new Cop group</a></li><li>My Group</li><li>View Join Group</li></ul></div>
      </div>
      <div id="side-panel-bottom"></div>
    </div>
    <?php
	}
	?>
   <!-- close -->
   
    <!--newest group-->
    <div class="grid_4 alpha" style="margin-top:8px;">
      <div id="side-panel-top">
      	<div style="padding-left: 22px; padding-top: 7px; font-weight: bold; color:#009933;">Newest Group</div>
      </div>
      <div id="side-panel-middle">
      	<div id="list" style="padding-left:25px; width:240px">
        <ol>
		<?php
			$this->db->order_by('create_date','desc');
			$this->db->limit(5);
			$q_newest_group = $this->db->get('cops_group');
			foreach($q_newest_group->result() as $q_n){
		?>
        <li><a href="<?=base_url()?>cops/groups/<?=$q_n->group_id?>"><?=$q_n->group_name?></a></li>
        <?php	
			}
		?>
        </ol>
        </div>
      </div>
      <div id="side-panel-bottom"></div>
    </div>
    <!--close-->
 </div>
<!--ปิดเมนูข้าง-->

  <div class="grid_8 omega">
  <!-- List cops -->
    <div class="grid_8 alpha" style="margin-top:10px;">
    <div id="km-topic">
    	<div style="padding-left: 15px; padding-top: 8px; font-weight: bold; color:#333333;">List of Community of Pratice</div>
    </div>
    
    <!-- begin middle -->
    <div id="km-new-middle">
    	<style type="text/css" media="screen"> 
			#pagination a, #pagination strong {
			 background: #E0E0E0;
			 padding: 2px 6px;
			 text-decoration: none;
			border: 1px solid #747474;
			color: #666666;
			font-size: 11px;
			}
			#pagination strong, #pagination a:hover {
			 font-weight: normal;
			 background: #1ECECE;
			}		
		</style>
    	<div id="pagination" style="padding-left:12px;"><?=$paginator?></div>
    	<?php
			//begin query
				/*$this->db->join('membership','membership.member_id=cops_group.owner');
				$this->db->order_by('create_date','desc');
				
				$q_list_cops = $this->db->get('cops_group');*/
				
				foreach($query->result() as $q_query)
				{
					$group_id = $q_query->group_id;
					
					//count member in group by id
					$this->db->where('group_id',$q_query->group_id);
					$co1 = $this->db->get('cops_group_in');
					$member_count= $co1->num_rows();
					
					//files count
					$this->db->where('group_id',$q_query->group_id);
					$q_d_count = $this->db->get('cops_files');
					$files_count = $q_d_count->num_rows();
					
					//query check into group ? if 1 == in group ready
					$this->db->where('member_id',$this->session->userdata('member_id'));
					$this->db->where('group_id',$q_query->group_id);
					$co = $this->db->get('cops_group_in');
					$m_chk = $co->num_rows();
		?>
        
         <!-- join button -->
           <script type="text/javascript">
		   		/*join group*/
				function confirm_join($id){
					var group_id = $id;
					var join_return = confirm("You confirm to join this group ?");
					if (join_return==true){
						window.location.href = "<?=base_url()?>cops/join/agreement/"+group_id;
						//alert(group_id);
					}
				}
				
				/*leave group*/
				function leave_join($id){
					var group_id = $id;
					var leave_return = confirm("Confirm to leave this group ?");
					if (leave_return==true){
						window.location.href = "<?=base_url()?>cops/leave/group/"+group_id;
						//alert(group_id);
					}
				}
		   </script>
           
        <div id="list_cops" style="padding-left:10px; width:580px; margin-top:10px; margin-left:6px; border-bottom:thin dashed #BCBCBC;">
      		<div id="cops_logo" style="float:left; height:150px; width:125px;">
            	<?php
					if($q_query->logo=="blank"){
				?>
               		<img src="<?=base_url()?>km_resource/cops_group/1294843267_people.png" width="120" height="115" style="padding:2px; border:thin groove #E5E5E5;"/>
                <?php
				}else{
				?>
                	<img src="<?=base_url()?>km_resource/cops_group/logo/<?=$q_query->logo?>" width="120" height="115" style="padding:2px; border:thin groove #E5E5E5;"/>
                <?php
				}
				?>
                <div id="join" style="margin-top:5px;">
                	 <?php
					 
						if($this->session->userdata('is_logged_in')&&($q_query->owner!=$this->session->userdata('member_id'))&&($m_chk==0)){
					  ?>
                <!-- join button-->    
                        <div id="join_group" style="width:123px; border:thin outset #50D1DC; cursor:pointer; background:#05B8C7; color:#FFFFFF; text-align:center; font-weight:bold;" onclick="confirm_join(<?=$group_id?>)">Join Group</div>
                <!-- close join button-->
					<?php
                    }
					else if($this->session->userdata('is_logged_in')&&($q_query->owner!=$this->session->userdata('member_id'))&&($m_chk==1)){
					?>
                    <!-- leave button-->
                    <div id="leave_group" style="width:123px; border:thin outset  #E9A527; cursor:pointer; background:#ECA94F; color:#FFFFFF; text-align:center; font-weight:bold;" onclick="leave_join(<?=$group_id?>)">Leave Group</div>
                    <?php
                    }
                    ?>
            <!-- close leave button-->
                </div>
            </div>
            <div id="cops_details" style="width:440px; float:right;">
            	<!-- topic -->
            	<div style="font-size:17px; font-weight:bold; color:#666666;"><a href="<?=base_url()?>cops/groups/<?=$q_query->group_id?>"><?=character_limiter($q_query->group_name,30)?></a></div>
                
                <!-- description -->
            	<div id="description"><strong>Description:</strong>&nbsp;<?=character_limiter(htmlspecialchars_decode($q_query->description),250)?></div>
                
                <!-- member counts -->
                <div id="member_counts"><strong>Member:</strong>&nbsp;(<?=$member_count?>)</div>
                
                <!-- files counts -->
                <div id="files_counts"><strong>Files:</strong>&nbsp;(<?=$files_count?>)</div>
                
                <!-- create date -->
                <div id="create_dated"><strong>Create Date:</strong>&nbsp;<?=$q_query->create_date?></div>
                
                <!-- owner -->
                <div id="create_dated"><strong>Create By:</strong>&nbsp;<?=$q_query->firstname?>&nbsp;<?=$q_query->lastname?>&nbsp;(<?=$q_query->nickname?>)</div>
            </div>
            <div id ="clear_both" style="clear:both;">&nbsp;</div>
        </div>
        <?php
			}	//end foreach
		?>
    </div>
        
    <div id="km-new-bottom"></div>
  </div>
  <!-- close -->
  
  <!-- set 2-->
  <div class="grid_8 alpha" style="margin-top:8px;">
    <div id="km-topic">
    	<div style="padding-left: 15px; padding-top: 11px; color: rgb(0, 0, 0); font-weight: bold; text-shadow: 1px 1px 1px rgb(255, 255, 255);">dfdsf</div>
    </div>
    <div id="km-new-middle">blog</div>
    <div id="km-new-bottom"></div>
  </div>
  <!-- close set 2-->
  
</div>
</div>

<div class="clear"></div>
<!--end content1-->
<div class="grid_12" style="background-color:#CCCCCC;">&nbsp;</div>
<div class="clear"></div>
<?php $this->load->view('inc/footer'); ?>